package com.zy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.domain.ReleaseTask;
import com.zy.mapper.ReleaseTaskMapper;
import com.zy.param.ReleaseTaskParam;
import com.zy.service.ReleaseTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class ReleaseTaskServiceImpl extends ServiceImpl<ReleaseTaskMapper, ReleaseTask> implements ReleaseTaskService {

  @Autowired
  private ReleaseTaskMapper releaseTaskMapper;


  @Override
  public ReleaseTask releaseTask(ReleaseTaskParam releaseTaskParam) {
    ReleaseTask releaseTask = new ReleaseTask();
    releaseTask.setUid(UUID.randomUUID().toString());
    releaseTask.setName(releaseTaskParam.getName());
    releaseTask.setType(releaseTaskParam.getType());
    releaseTask.setNum(releaseTaskParam.getNum());
    releaseTask.setMatchNum(0);
    releaseTask.setMoney(releaseTaskParam.getMoney());
    releaseTask.setUrl(releaseTaskParam.getUrl());
    releaseTask.setRemarks(releaseTaskParam.getRemarks());
    releaseTask.setEndTime(releaseTaskParam.getEndTime());
    releaseTask.setState(0);
//    releaseTask.setDetail(releaseTaskParam.getDetail());
    releaseTask.setImg01(releaseTaskParam.getImg01()==null?"":releaseTaskParam.getImg01());
    releaseTask.setImg02(releaseTaskParam.getImg02()==null?"":releaseTaskParam.getImg02());
    releaseTask.setImg03(releaseTaskParam.getImg03()==null?"":releaseTaskParam.getImg03());
    releaseTask.setImg04(releaseTaskParam.getImg04()==null?"":releaseTaskParam.getImg04());
    releaseTask.setOiimg01(releaseTaskParam.getOiimg01()==null?null:releaseTaskParam.getOiimg01());
    releaseTask.setOiimg02(releaseTaskParam.getOiimg02()==null?null:releaseTaskParam.getOiimg02());
    releaseTask.setOiimg03(releaseTaskParam.getOiimg03()==null?null:releaseTaskParam.getOiimg03());
    releaseTask.setOiimg04(releaseTaskParam.getOiimg04()==null?null:releaseTaskParam.getOiimg04());
    releaseTask.setOiimg05(releaseTaskParam.getOiimg05()==null?null:releaseTaskParam.getOiimg05());
    releaseTask.setOitext01(releaseTask.getOitext01()==null?null:releaseTaskParam.getOitext01());
    releaseTask.setOitext02(releaseTask.getOitext02()==null?null:releaseTaskParam.getOitext02());
    releaseTask.setOitext03(releaseTask.getOitext03()==null?null:releaseTaskParam.getOitext03());
    releaseTask.setOitext04(releaseTask.getOitext04()==null?null:releaseTaskParam.getOitext04());
    releaseTask.setOitext05(releaseTask.getOitext05()==null?null:releaseTaskParam.getOitext05());
    releaseTask.setDeleteState("Y");//可以使用
    releaseTask.setTop("N");
    releaseTask.setTopTime(null);

    int insert = releaseTaskMapper.insert(releaseTask);
    return releaseTask;
  }

  @Override
  public ReleaseTask getTaskById(Integer id) {
    LambdaQueryWrapper<ReleaseTask> eq = new LambdaQueryWrapper<ReleaseTask>().eq(ReleaseTask::getId, id);
    ReleaseTask releaseTask = releaseTaskMapper.selectOne(eq);
    return releaseTask;
  }
}
